import {Injectable} from '@angular/core';
import {Http, Headers, RequestOptions, RequestOptionsArgs} from '@angular/http';
import {adSystemApiUrl, tpType} from '../../../config/api';
import {HttpService} from '../../lib/service/http.service';
import {LocalStorageService} from '../../lib/service/local-storage.service';

@Injectable()
export class AppletSettingService {

  constructor(private httpService: HttpService, private localStorageService: LocalStorageService) {
  }

  // 获取支付信息
  getPayment() {
    const applet = this.localStorageService.getNowApplet();
    const url = `${adSystemApiUrl}/v1/member/applets/getPaymentSetting?applet_id=${applet.id}`;
    return this.httpService.httpPostAuth(url, {}).map(res => res);
  }

  // 绑定支付系统
  bindPaySubmit(body) {
    const url = `${adSystemApiUrl}/v1/member/applets/payment_setting`;
    return this.httpService.httpPostAuth(url, body).map(res => res);
  }

  // 获取微信预授权码
  gotoWechatGetAuthorization() {
    const url = `${adSystemApiUrl}/v1/member/wechat/pre_auth_code`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }

  // 获取微信详情
  getAuthorizationInfo(body) {
    const url = `${adSystemApiUrl}/v2/member/wechat/get_authorization_info_v2`;
    // const url = `http://rap2api.taobao.org/app/mock/8894/POST/v1/member/wechat/get_authorization_info_v2`;
    return this.httpService.httpPostAuth(url, body).map(res => res);
  }
  setWebviewdomain(applet_uuid){
    const url=`${adSystemApiUrl}/v1/member/wechat/webview_auth`;
    return this.httpService.httpPostAuth(url,{}).map(res => res);
  }
  // 获取小程序版本信息
  getAppletVersion() {
    const url = `${adSystemApiUrl}/v2/member/template/applet_version`;
    // const url = `http://rap2api.taobao.org/app/mock/8894/GET/v1/member/wechat/applet_version`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }

  // 获取小程序版本列表
  getAppletVersionList(page) {
    const url = `${adSystemApiUrl}/v2/member/wechat/commit_record_v2?page=${page}`;
    // const url = `http://rap2api.taobao.org/app/mock/8894/GET/v1/member/wechat/commit_record_v2?page=${page}`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }

  // 提交审核
  submitAudit() {
    const url = `${adSystemApiUrl}/v1/member/wechat/submit_audit`;
    return this.httpService.httpPostAuth(url, {}).map(res => res);
  }

  // 打包并发布小程序
  makePackPublish() {
    const url = `${adSystemApiUrl}/v2/member/wechat/make_pack_publish`;
    return this.httpService.httpPostAuth(url, {}).map(res => res);
  }

  // 查看审核结果
  getAuditstatus(id, auditid) {
    const url = `${adSystemApiUrl}/v2/member/wechat/get_auditstatus_v2`;
    return this.httpService.httpPostAuth(url, {id: id, auditid: auditid}).map(res => res);
  }

  // 获取小程序配置
  getNowApplet() {
    const applet = this.localStorageService.getNowApplet();
    const url = `${adSystemApiUrl}/v1/member/applets/detail?uuid=${applet.applet_uuid}`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }
}
